<?php
namespace Admin\Controller;
use Think\Controller;
class ManageController extends CommonController 
{	
	//管理员登录
	public function login()
	{
		if(IS_AJAX)
		{
			$msg = array();
			$msg['status'] = 'error';
			$veri = $this -> check_verify(I('verify'));
			//验证码验证
			if(!empty($veri)){
				$manage = D('manage');
				$result = $manage->check(I('username'),I('password'));

				if(!empty($result)){
					//账号密码正确
					session('manage_id',$result['id']);
					session('manage_name',$result['username']);
					$msg['code'] = 1;
					$msg['info'] = '登录成功';
					$msg['status'] = 'success';
					$this->ajaxReturn($msg);
				}else{
					//账号密码错误
					$msg['code'] = 2;
					$msg['info'] = '账号密码不匹配';
					$msg['status'] = 'error';
					$this->ajaxReturn($msg);
				}

			}else{
				//验证码错误
				$msg['code'] = 0;
				$msg['info'] = '验证码错误';
				$this -> ajaxReturn($msg);
			}
		}
		
		$this -> display();
	}
	// public function through(){

	// 	$mod = M('users');
	// 	$result = $mod -> select();
	// }

	public function logout()
	{
		session(null);
		// $this->success();
		// $this->error();
		//重定向
		// $this->redirect('admin/manage/login');
		$this->redirect('login');

	}

	public function verify()
	{

		$config   = array(
			'fontSize'  =>   50,
			'length'    =>   4,
			'codeSet'   => '0123456789',
		);

		$Verify = new \Think\Verify($config);
		$Verify->entry();
	}
	//验证码验证
	public function check_verify($code, $id = '')
	{
	    $verify = new \Think\Verify();

	    return $verify->check($code, $id);
	}
} 

	





?>